import axios from 'axios'
import QS from 'qs'
import {http8090} from './devlocalport'
const baseURL = http8090
const instance = axios.create({
    timeout: 20000,
    baseURL,
    headers: {
        'Content-Type': "application/json"
    }
});
const instance1 = axios.create({
    timeout: 20000,
    responseType: "blob",
    baseURL,
    headers: {
        'Content-Type': "application/json",
    }
});
const proposal = axios.create({
    timeout: 20000,
    baseURL,
    headers: {
        'Content-Type': "application/x-www-form-urlencoded"
    }
});

const upfile = axios.create({
    timeout: 20000,
    baseURL,
    headers: {
        'Content-Type': 'multipart/form-data'
    }
});
instance.interceptors.request.use(
    config => {
     config.headers['Authorization'] = sessionStorage.getItem('token_12')
      return config
    },
    error => {
      return Promise.reject(error)
    }
  )
  instance1.interceptors.request.use(
    config => {
     config.headers['Authorization'] = sessionStorage.getItem('token_12')
      return config
    },
    error => {
      return Promise.reject(error)
    }
  )
  proposal.interceptors.request.use(
    config => {
     config.headers['Authorization'] = sessionStorage.getItem('token_12')
      return config
    },
    error => {
      return Promise.reject(error)
    }
  )

  upfile.interceptors.request.use(
    config => {
     config.headers['Authorization'] = sessionStorage.getItem('token_12')
      return config
    },
    error => {
      return Promise.reject(error)
    }
  )
export function get(url, params) {
    return new Promise((resolve, reject) => {
        instance.get(url, {
            params: params
        }).then(res => {
            resolve(res.data);
        }).catch(err => {
            reject(err.data)
        })
    });
}
export function post(url, params) {
    return new Promise((resolve, reject) => {
        proposal.post(url, QS.stringify(params))
            .then(res => {
                resolve(res.data);
            })
            .catch(err => {
                reject(err.data)
            })
    });
}
export function post_json(url, params) {
    return new Promise((resolve, reject) => {
        instance.post(url, params)
            .then(res => {
                resolve(res.data);
            })
            .catch(err => {
                reject(err.data)
            })
    });
}
export function post_json1(url, params) {
    return new Promise((resolve, reject) => {
        instance1.post(url, params)
            .then(res => {
                resolve(res.data);
            })
            .catch(err => {
                reject(err.data)
            })
    });
}
export function post_form(url, params) {
    return new Promise((resolve, reject) => {
        upfile.post(url, params)
            .then(res => {
                resolve(res.data);
            })
            .catch(err => {
                reject(err.data)
            })
    });
}